/*
 * @Author: Troubadour 2276791354@qq.com
 * @Date: 2024-03-30 16:30:50
 * @LastEditors: Troubadour 2276791354@qq.com
 * @LastEditTime: 2024-04-11 19:37:42
 * @Version:
 * @Description:
 */

#ifndef __ESP_01_H__
#define __ESP_01_H__

#include "main.h"
#include "DeskLamp.h"

#define WIFI_BUFFER_NUM     (5)
#define WIFI_BUFFER_SIZE    (400)

typedef enum
{
    WIFI_RST = 0,
    WIFI_INIT,
    WIFI_CNT,
    WIFI_MQTT_CFG,
    WIFI_MQTT_CNT,
    WIFI_MQTT_SUB,
    WIFI_MQTT_WORK,
    WIFI_BUSY,
}WIFI_ENUM;

typedef struct
{
    WIFI_ENUM state;
    uint8_t waitData;
    uint8_t *response;
}ESP_01_TyP;

typedef struct
{
    uint8_t buf[WIFI_BUFFER_SIZE];
    uint16_t size;
    uint8_t UseFlag;
}ESP_Buf_TyP;

typedef struct
{
    uint8_t client_Id;
    uint8_t topic[128];
    uint16_t payloadlen;
    uint8_t payload[256];
}MQTTData;

/* 设备上传数据 */
typedef struct
{
    uint8_t powerstate; /* Key state */
    TASK_MODE_ENUM mode;   /* 运行模式 */
    uint8_t brightness; /* 亮度 */
    float Ultra;    /* 测距 */
    LED_COLOR_ENUM Color;  /* 颜色 */
    uint8_t ManSensor;  /* 人体红外感应 */
    uint32_t SRuntime;  /* 实时时间 */
    uint8_t LED_State;  /* LED状态 */
    uint32_t RecordSitTime;
    int time_y;  /* 年 */
    int time_d;  /* 天 */
    int time_h;  /* 小时 */
    int time_m;  /* 分钟 */
    int time_s;  /* 秒 */
}DeviceReport;


extern DeviceReport deviceUpReport;
extern ESP_Buf_TyP WiFiBufDataQueue[WIFI_BUFFER_NUM];


void Esp_01_Task(void);
void Esp_01_RecvHandle(uint8_t *recvBuf, uint16_t len);



#endif  /*  __ESP_01_H__  */

